﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace SMS
{
    public partial class fThongtintaikhoan : Form
    {
        fLogin main;
        public fThongtintaikhoan(fLogin main1)
        {
            InitializeComponent();
            Loadinfor();
            main = main1;
        }
       

        private void bntHuy_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            bntLuu.Visible = false;
            picSua.Visible = false;
            picThongtintk.Visible = true;
            btnCapnhat.Visible = true;
            txtMaTK.Enabled = false;
            txtMatKhau.Enabled = false;
            txtTenTK.Enabled = false;
        }
        
        private void btnCapnhat_Click(object sender, EventArgs e)
        {
            bntLuu.Visible = true;
            btnCapnhat.Visible = false;
            picSua.Visible = true;
            picThongtintk.Visible = false;

            
            txtMatKhau.Enabled = true;
            txtTenTK.Enabled = true;
            
            
        }
        //private DataTable show()
        //{
        //    // show sau khi chạy
        //    SqlDataAdapter da;
        //    DataTable dt = new DataTable();
        //    //KetNoiDataBase db = new KetNoiDataBase();
        //    SqlConnection con = main.KetNoiDB.GetConServer();
        //    //da = new SqlDataAdapter("SELECT * FROM NGUOIDUNG ", con);
        //    da = new SqlDataAdapter("SELECT MATK as 'Mã Tài Khoản',TENTK as 'Tên Tài Khoản',MATKHAUMD as 'Mật Khẩu' FROM TAIKHOAN ", con);
        //    dt.Clear();
        //    da.Fill(dt); // do ket qua truy van vao ban
        //    return dt;
        //}

        private void bntLuu_Click(object sender, EventArgs e)
        {

            bntLuu.Visible = false;
            picSua.Visible = false;
            picThongtintk.Visible = true;
            btnCapnhat.Visible = true;
            txtMatKhau.Enabled = false;
            txtTenTK.Enabled = false;

            SqlConnection conn = new SqlConnection(main.ConnectDB);
            SqlCommand command =new SqlCommand();
            command.Connection=conn;
            command.CommandText="UPDATE TAIKHOAN SET MATKHAUMD =@matkhau, TENTK=@tentk WHERE MATK=@matk";

            command.Parameters.Add(new SqlParameter("@tentk", txtTenTK.Text.ToString()));
            command.Parameters.Add(new SqlParameter("@matkhau", txtMatKhau.Text.ToString()));
            command.Parameters.Add(new SqlParameter("@matk", txtMaTK.Text.ToString()));

                try
                {
                    
                    conn.Open();
                    
                    //sc.Connection()CO= new SqlCommand( ='"+txtTenTK.Text+"'");
                    command.ExecuteNonQuery();
                    MessageBox.Show("Cập nhật thành công!", "thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("Cập nhật thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                main.Danhsachtaikhoan.updateDSTK();
                     
        }

        private void fThongtintaikhoan_Load(object sender, EventArgs e)
        {
            bntLuu.Visible = false;
            picSua.Visible = false;

        }
        private void Loadinfor()
        {


        }
    }
}
